<template>
  <div class="box">
    <div id="el-login-footer">
      <span
        >© 2018-2022 YSHOP
        <a href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank"
          >All Rights Reserved</a
        ></span
      >
      <span> ⋅ </span>
      <a href="http://beian.miit.gov.cn" target="_blank">豫ICP备17049587-2号</a>
    </div>

    <div class="six">
      <div
        class="box1"
        style="
          display: flex;
          justify-content: space-between;
          align-items: center;
        "
      >
        <div style="padding: 0px 60px 0px 0px">
          <h3
            style="
              color: rgb(255, 255, 255);
              font-size: 24px;
              padding: 0px;
              margin-bottom: 10px;
            "
          >
            YSHOP单商户B2C电商系统
          </h3>
          <ul
            style="
              margin: 0px;
              color: rgb(255, 255, 255);
              font-size: 15px;
              line-height: 25px;
              padding-left: 20px;
            "
          >
            <li>Springboot2</li>
            <li>MybatisPlus</li>
            <li>SpringSecurity</li>
            <li>Jwt</li>
            <li>Redis</li>
            <li>Vue</li>
          </ul>
          <h3 style="color: rgb(255, 255, 255)">官网:https://www.yixiang.co</h3>
        </div>
      </div>

      <div class="box2">
        <h3 class="h3">YSHOP后台管理系统-3.2</h3>

        <el-form
          :model="form"
          label-width="100px"
          :rules="rules"
          ref="ruleFormRef"
        >
          <el-form-item label="账号" prop="name">
            <el-input v-model="form.name" placeholder="请输入账号" />
          </el-form-item>
          <el-form-item label="密码" prop="pwd">
            <el-input
              v-model="form.pwd"
              type="password"
              placeholder="请输入密码"
            />
          </el-form-item>
          <el-form-item label="确定密码" prop="pwds">
            <el-input
              v-model="form.pwds"
              type="password"
              placeholder="确认密码"
            />
          </el-form-item>
          <el-form-item label="">
            <el-checkbox v-model="form.bool">记住我</el-checkbox>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="onSubmit">登录</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
import { Login } from '@a/login'
export default {
  name: 'LoginPage',
  data () {
    return {
      form: {
        name: '',
        pwd: '',
        pwds: '',
        bool: false
      },
      rules: {
        name: [
          {
            required: true,
            message: '账号必填'
          }
        ],
        pwd: [
          {
            required: true,
            message: '密码必填'
          },
          {
            pattern: /[a-zA-Z]\w{3,7}/,
            message: '4-8英文数字字母_注册,字母开头'
          }
        ],
        pwds: [
          {
            required: true,
            message: '确定密码必填'
          },
          {
            pattern: /[a-zA-Z]\w{3,7}/,
            message: '4-8英文数字字母_注册,字母开头'
          }
        ]
      }
    }
  },
  methods: {
    onSubmit () {
      if (this.form.pwd !== this.form.pwds) {
        this.$message({
          type: 'error',
          message: '两次密码不正确'
        })
        return
      }

      this.$refs.ruleFormRef.validate().then(res => {
        Login({ form: this.form }).then(res => {
          console.log(res)
          if (res.data.code === 200) {
            const { role, token, userInfo } = res.data.data
            localStorage.setItem('role', role)
            localStorage.setItem('token', token)
            localStorage.setItem('userInfo', JSON.stringify(userInfo))
            this.$store.commit('base/INIT_USER', res.data.data)
            this.$message({
              type: 'success',
              message: res.data.msg,
              duration: 1500,
              onClose: () => {
                this.$router.replace('/dashBoard')
              }
            })
          }
        })
      }).catch(res => {
        this.$message({
          type: 'error',
          message: '验证失败'
        })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.six {
  position: absolute;
  top: 30%;
  left: 30%;
  display: flex;

  .box2 {
    width: 300px;
    position: relative;
    // top: -30px;
    border-radius: 6px;
    background: #fff;
    width: 385px;
    padding: 25px 25px 5px 0;
  }

  .h3 {
    display: block;
    font-size: 1.17em;
    margin-block-start: 1em;
    margin-block-end: 1em;
    margin-inline-start: 0px;
    margin-inline-end: 0px;
    font-weight: bold;
    margin: 0 auto 30px auto;
    text-align: center;
    color: #707070;
  }
}

.box {
  position: relative;
  width: 100vw;
  height: 100vh;
  background-image: url("../../assets/image/dalogo.jpg");
  background-repeat: no-repeat;
  background-size: cover;
}

#el-login-footer {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  box-sizing: inherit;
  height: 40px;
  line-height: 40px;
  text-align: center;
  color: #fff;
  font-family: Arial, serif;
  font-size: 12px;
  letter-spacing: 1px;
  position: fixed;
  bottom: 0;
  width: 100%;

  span {
    line-height: 40px;
    text-align: center;
    color: #fff;
    font-family: Arial, serif;
    font-size: 12px;
    letter-spacing: 1px;
  }

  a {
    cursor: pointer;
    color: inherit;
    text-decoration: none;
  }
}
</style>
